/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// peditfld.hpp - PegEditField class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGEDITFLD_
#define _PEGEDITFLD_


typedef struct {
    PEGUSHORT mEditMode:1;
    PEGUSHORT mMarked:1;
    PEGUSHORT mFullSelect:1;
    PEGUSHORT mMarkMode:1;
    PEGUSHORT mChanged:1;
} StateFlags;


class PegEditField : public PegTextThing
{
    public:

        PegEditField(const PegRect &Rect,
                     PEGUINT StringId = 0,
                     PEGUSHORT Id = 0,
                     PEGULONG Style = FF_RECESSED|AF_ENABLED|EF_EDIT,
                     PEGINT Len = -1);

        PegEditField(const PEGCHAR *pText,
                     const PegRect &Rect,
                     PEGUSHORT Id = 0,
                     PEGULONG Style = FF_RECESSED|AF_ENABLED|EF_EDIT,
                     PEGINT Len = -1);

        virtual ~PegEditField();

        void CopyToScratchPad(void);
        

        virtual void DataSet(PEGUINT StringId);
        virtual void DataSet(const PEGCHAR *Text);
 
        void DeleteMarkedText(void);
        virtual void Draw(const PegRect &Invalid);

        virtual PEGINT GetMarkEnd(void) {return mMarkEnd;}
        virtual PEGINT GetMarkStart(void) {return mMarkStart;}

        PEGINT GetMaxLen(void);

        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void ParentShift(PEGINT x, PEGINT y);

        void PasteFromScratchPad(void);
        virtual void SetMark(PEGINT Start, PEGINT End);
        virtual void SetMark(PEGCHAR *pMarkStart, PEGCHAR *pMarkEnd);

        void SetMaxLen(PEGINT Length);

        virtual void SetStyle(PEGULONG Style);



    protected:
        virtual void AdvanceCursor(PEGINT New);

       #ifdef PEG_KEYBOARD_SUPPORT
        PEGBOOL CheckControlKey(PEGINT Key, PEGINT Flags);
       #endif

        virtual void DrawMarked(void);
        virtual void Initialize(PEGULONG Style);
        virtual PEGBOOL InsertKey(PEGINT Key);
        void ReplaceMarkedText(PEGINT Key);
        virtual void RetardCursor(PEGINT New);
        virtual void SetCursorPos(PegPoint PickPoint);


        PegPoint mCursorPos;

        union
        {
            StateFlags State;
            PEGUBYTE mFullState;
        };

       #ifdef PEG_KEYBOARD_SUPPORT
        PEGCHAR *mpBackup;
       #endif

        PEGINT mCursor;
        PEGINT mMarkAnchor;
        PEGINT mMarkStart;
        PEGINT mMarkEnd;
        PEGINT mFirstVisibleChar;
        PEGINT mMaxLen;

};


#endif

